package com.fastshopping.model.controller;

import com.fastshopping.model.service.ModelService;
import com.wink.entity.Result;
import com.wink.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;

import com.fastshopping.order.pojo.Model;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Name: 李袁勇
 * @Date: 2020/6/5 9:46
 * @Version: 1.0
 **/

@RestController
@RequestMapping("/model")
public class ModelController {

    @Autowired
    private ModelService modelService;

    /*
    * 查询店铺自己的模板*/
    @RequestMapping("/findMyModel")
    public Result findMyModel(int user_id){
        try {
            List <Model> myModel = modelService.findMyModel(user_id);
            return new Result(true, StatusCode.OK,"查询成功",myModel);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    /*
    * 查询自己购买的模板*/
    @RequestMapping("/findBuyModel")
    public Result findBuyModel(int user_id){
        try {
            List <Model> buyModel = modelService.findBuyModel(user_id);
            return new Result(true, StatusCode.OK,"查询成功",buyModel);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    /*
    * 查询所有的类别名称*/
    @RequestMapping("/findAllCategory")
    public Result findAllCategory(){
        try {
            List <Map> mapList = modelService.findAllCategory();
            return new Result(true, StatusCode.OK,"查询成功",mapList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    /*
    * 根据类别名称查询模板信息*/
    @RequestMapping("/findOneCategory")
    public Result findOneCategory(int user_id,String category){
        try {
            List <Model> oneCategory = modelService.findOneCategory(user_id, category);
            return new Result(true, StatusCode.OK,"查询成功",oneCategory);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    /*
    * 根据商品名称查询所有的模板*/
    @RequestMapping("/findTbName")
    public Result findTbName(int user_id,String tb_name){
        try {
            List <Model> tbName = modelService.findTbName(user_id, tb_name);
            return new Result(true, StatusCode.OK,"查询成功",tbName);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    /*
    * 查询所有子类名*/
    @RequestMapping("/findBuyCategory")
    public Result findBuyCategory(){
        try {
            List <Map> buyCategory = modelService.findBuyCategory();
            return new Result(true, StatusCode.OK,"查询成功",buyCategory);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    /*
    * 根据类别名称查询子类名*/ 
    
    @RequestMapping("/findCategoryByBuy")
    public Result findCategoryByBuy(int user_id,String category){
        try {
            List <Map> categoryByBuy = modelService.findCategoryByBuy(user_id, category);
            return new Result(true, StatusCode.OK,"查询成功",categoryByBuy);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }


    /*
    * 子类名下的所有模板*/
    @RequestMapping("/findAllBuy")
    public Result findAllBuy(int user_id,String sub_category){
        try {
            List <Model> allBuy = modelService.findAllBuy(user_id, sub_category);
            return new Result(true, StatusCode.OK,"查询成功",allBuy);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    
}
